<?php

namespace App\Service\Activity\v1_3_0;

use App\Helpers\AliyunUtil;
use App\Model\Act\SigninLog;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 签到信息
 */
class SigninPopService extends BaseService
{
    public function handle()
    {
        //屏蔽APP包
        if (in_array($this->appId, explode(',', env('SIGNIN_POP_FORBID_APPID', '6')))) return [];

        #TODO 屏蔽签到弹框
        if ($this->appId == 102) {
            return [];
        }

        $userId = $this->getUserId();
        $profile = UserProfile::getProfile($userId);
        //主播不显示签到弹窗
        if ($profile->gender != 1) return [];
        $lastItem = SigninLog::getLastItem($userId);
        //连续签到天数
        $signDay = SigninLog::getSignInDay($lastItem);
        $signList = SigninLog::packRewardList();
        foreach ($signList as &$item) $item['signined'] = $item['day'] <= $signDay ? 1 : 0;
        $todaySign = SigninLog::checkToday($lastItem);
        $showPop = $todaySign ? 0 : 1;

        $ret = [
            'show' => $showPop,
            //今天是否签到
            'signin_today' => $todaySign,
            //已连续签到天数
            'signin_days' => $signDay,
            //礼物列表
            'signin_list' => $signList,
        ];
        //签到提示
        return $ret;
    }
}
